package com.crm.common.helper;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @description:
 * @author: lixq-f
 * @create: 2021/03/31
 */
@Accessors(chain = true)
public class PageHelper<T> implements Serializable {
    @Setter
    @Getter
    private String code;
    @Setter
    @Getter
    private String message;

    /**
     * 页码，从1开始
     */
    @Setter
    @Getter
    private int pageIndex;
    /**
     * 页面大小
     */
    @Setter
    @Getter
    private int pageSize;

    /**
     * 总数
     */
    @Setter
    @Getter
    private long totalRecords;


    /**
     * 总页数
     */
    @Setter
    private int totalPages;

    /**
     * 数据
     */
    @Setter
    @Getter
    private List<T> data;


    public int getTotalPage() {
        if (pageSize <= 0) {
            return 1;
        } else {
            return (int) (totalRecords % pageSize == 0 ? (totalRecords / pageSize) : (totalRecords / pageSize) + 1);
        }

    }




}
